<template>
	<div id="sickperson">

		<!-- 新增患者 -->
		<el-row style="margin-bottom: 10px;">
			<el-col :span="7" style="right">
				<el-button @click="insertData" style="background-color: cornflowerblue; font-size: 17px;margin-left: 980px;" type="primary">
					<i class="el-icon-circle-plus" style="color: #EAEAEA;">
						<font color="#EAEAEA">新增患者</font>
					</i>
				</el-button>
			</el-col>
		</el-row>


		<!-- 查询 -->
		<el-row>
			<el-col :span="24">
				<el-form :inline="true" :model="searchForm" class="demo-form-inline">

					<el-form-item label="会员类型">
						<el-select v-model="searchForm.vipgradeId" placeholder="全部" style="color: gold;">
							<i>
								<b>
									<el-option v-for="vip in vipgrade" :label="vip.viplevel" :value="vip.id" style="color: gold;"></el-option>
								</b>
							</i>
						</el-select>
					</el-form-item>

					<el-form-item label="创建时间">
						<el-date-picker v-model="searchForm.value" value-format="yyyy-MM-dd" type="daterange" range-separator="至"
						 start-placeholder="开始日期" end-placeholder="结束日期">
						</el-date-picker>
					</el-form-item>
					<el-form-item>
						<el-input v-model="searchForm.sname" placeholder="患者姓名/手机号码"></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="searchData">🔍</el-button>
					</el-form-item>
				</el-form>
			</el-col>
		</el-row>


		<!-- 列表 -->
		<template>
			<el-table :data="tableData" style="width: 100%">
				<el-table-column prop="id" label="序号" width="90"></el-table-column>
				<el-table-column prop="serialnumber" label="患者编码" width="100"></el-table-column>
				<el-table-column prop="name" label="患者姓名" width="90"></el-table-column>
				<el-table-column label="性别" width="90">
					<template v-slot="scope">
						{{scope.row.sex=='0'?'男':'女'}}
					</template>
				</el-table-column>
				<el-table-column prop="age" label="年龄" width="90"></el-table-column>
				<el-table-column prop="phone" label="手机号码" width="120"></el-table-column>
				<el-table-column label="会员等级" width="100">
					<template v-slot="scope">
						<i><b style="font-size: 16px;color: gold;">{{scope.row.viplevel}}</b></i>
					</template>
				</el-table-column>
				<el-table-column prop="createtime" label="创建时间" width="110"></el-table-column>
				<el-table-column label="操作人员" width="110">
					<template v-slot="scope">
						{{scope.row.docname}}
					</template>
				</el-table-column>
				<el-table-column label="操作" width="460">
					<template v-slot="scope">
						<el-button type="infor" style="color: deepskyblue;" @click="admissionData(scope.row)">接诊</el-button>
						<el-button type="infor" style="color: deepskyblue;" @click="updateData(scope.row)">编辑</el-button>
						<el-button type="infor" style="color: deepskyblue;" @click="vipSetupData(scope.row)">设置会员</el-button>
						<el-button type="infor" style="color: deepskyblue;" @click="deleteByIds(scope.row.id)">删除</el-button>
					</template>
				</el-table-column>

			</el-table>
		</template>

		<!-- 分页 -->
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="current"
		 :page-sizes="sizes" :page-size="size" layout="total, sizes, prev, pager, next, jumper" :total="total" background>
		</el-pagination>


		<!-- 会员设置 -->
		<el-dialog :title="this.title" :visible.sync="dialogTableVisible" width="40%" center>
			<!-- <el-form :model="saveForm" ref="saveForm" :rules="rules" label-width="80px">
				</el-form> -->
			<template>
				<span style="font-size: 20px; margin-top: -20px;">设置会员等级</span> <br /><br />
				会员卡号: 会员姓名: <br /><br />
				到期时间: <br /><br />
				<table :data="viptableData">
					<!-- <el-radio></el-radio> -->
					<el-table-column prop="viplevel" label="会员等级" width="180"></el-table-column>
					<el-table-column prop="name" label="会员名称" width="180"></el-table-column>
					<el-table-column prop="vipdiscount" label="折扣"></el-table-column>

				</table>
			</template>
		</el-dialog>


	</div>
</template>

<script>
	export default {
		data() {
			return {
				viptableData: [],
				dialogTableVisible: false,
				title: '会员设置',
				upd: '',
				insertDialog: false,
				insertFrm: {},
				title: '',
				value: '',
				vipgrade: [],
				searchForm: {},
				size: 6,
				sizes: [6, 8, 10],
				total: 0,
				current: 1,
				tableData: []
			}
		},
		created() {
			this.viptabData();
			this.initData();
			this.vipData();
		},
		methods: {
			admissionData(row) {
				//this.$router.push("/admission");

				this.$router.replace({
					path: '/admission',
					query: {
						admissionData: row,
						admiss: 1
					}
				})
			},
			viptabData() {
				this.axios.get('', {
					params: {

					}
				}).then((res) => {
					this.viptableData = this.res.data.obj;
				})
			},
			vipSetupData() {

				this.dialogTableVisible = true;


			},
			deleteByIds(ids) {
				this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then((res) => {

					this.axios.get('http://localhost:9993/sickperson/delete', {
						params: {
							ids: ids
						}
					}).then((res) => {
						this.initData();
						if (res.data) {
							this.$message({
								message: '删除成功',
								type: 'success'
							});

						} else {
							this.$message({
								message: '删除失败',
								type: 'success'
							});
						}
					})

				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});
			},
			updateData(row) {
				this.$router.replace({
					path: '/savesickperson',
					query: {
						updateData: row,
						upd: 1
					}
				})
			},
			insertData() {

				this.$router.push("/savesickperson")

				// this.$router.replace({
				// 	path: '/savesickperson',
				// })
			},
			searchData() {
				this.current = 1;
				this.initData();
			},
			vipData() {
				this.axios.get('http://localhost:9993/vipgrade/list').then(res => {
					this.vipgrade = res.data.obj;
				})
			},
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
				this.size = val;
				this.initData();
			},
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`);
				this.current = val;
				this.initData();
			},
			initData() {

				this.axios.get('http://localhost:9993/sickperson/list', {
					params: {
						size: this.size,
						current: this.current,
						vipgradeId: this.searchForm.vipgradeId,
						stime: this.searchForm.value ? this.searchForm.value[0] : '',
						etime: this.searchForm.value ? this.searchForm.value[1] : '',
						sname: this.searchForm.sname
					}
				}).then((res) => {
					this.tableData = res.data.obj.records;
					this.total = res.data.obj.total;
				})
			}
		}
	}
</script>
